/**
 * 
 */
package instant.openvfs.home;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * @author qiangli
 * 
 */
public final class Preferences {

	private static final String FLING_MODE = "fling_mode"; // 0: fling on, 1:
															// thumbnail, 2:
															// list

	public static final int FLING_ON = 0;
	public static final int FLING_THUMBNAIL = 1;
	public static final int FLING_LIST = 2;

	public static final String ENABLE_TTS = "settings.tts.toggle";

	public static int getFlingMode(Context ctx) {
		final int def = 0;
		try {
			final SharedPreferences pref = PreferenceManager
					.getDefaultSharedPreferences(ctx);
			return pref.getInt(FLING_MODE, def);
		} catch (Exception e) {
		}
		return def;
	}

	public static void putFlingMode(Context ctx, int mode) {
		final SharedPreferences pref = PreferenceManager
				.getDefaultSharedPreferences(ctx);
		pref.edit().putInt(FLING_MODE, mode).commit();
	}

	public static boolean ttsEnabled(Context ctx) {
		final boolean def = true;
		try {
			final SharedPreferences pref = PreferenceManager
					.getDefaultSharedPreferences(ctx);
			return pref.getBoolean(ENABLE_TTS, def);
		} catch (Exception e) {
		}
		return def;
	}

	private static final String LAST_PICK_PATH = "last_pick_path";

	private static final String LAST_PATH = "last_home_path";

	/**
	 * 
	 */
	public Preferences() {
		//
	}

	public static String getLastPickPath(Context ctx, String def) {
		try {
			final SharedPreferences pref = PreferenceManager
					.getDefaultSharedPreferences(ctx);
			return pref.getString(LAST_PICK_PATH, def);
		} catch (Exception e) {
		}
		return def;
	}

	public static void putLastPickPath(Context ctx, String path) {
		final SharedPreferences pref = PreferenceManager
				.getDefaultSharedPreferences(ctx);
		pref.edit().putString(LAST_PICK_PATH, path).commit();
	}

	public static String getLastPath(Context ctx, String def) {
		try {
			final SharedPreferences pref = PreferenceManager
					.getDefaultSharedPreferences(ctx);
			return pref.getString(LAST_PATH, def);
		} catch (Exception e) {
		}
		return def;
	}

	public static void putLastPath(Context ctx, String path) {
		final SharedPreferences pref = PreferenceManager
				.getDefaultSharedPreferences(ctx);
		pref.edit().putString(LAST_PATH, path).commit();
	}
}
